package cn.tpshion.devops.util;

import cn.tpshion.devops.common.enums.MsgType;
import cn.tpshion.devops.domain.entity.MsgData;
import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;

@Slf4j
public class TestUtil {

    public static void main(String[] args) throws Exception{
        StringBuilder command = new StringBuilder();
        command.append("docker run -i --rm --name test nginx:1.24.0 /bin/bash -c 'cd /usr && pwd && ls'");
        ProcessBuilder processBuilder = new ProcessBuilder("/bin/sh","-c", command.toString());
        processBuilder.redirectErrorStream(true);
        Process process = processBuilder.start();

        try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))){
            String line;
            while ((line = reader.readLine()) != null) {
                log.info("exec log:{}", line);
            }

            int exitCode = process.waitFor();
            log.info("LocalCommandHandle exec exitCode:{}", exitCode);
        }
    }
}
